<%@page contentType="text/html;charset=utf-8" pageEncoding="UTF-8" %>
<%@page import="org.ipo.mm.web.util.pager.AbstractPager, org.ipo.mm.web.util.ConstantManager, java.util.Collection, org.ipo.mm.web.util.security.SecurityManager, java.util.Vector" %>
<%@taglib prefix="l" uri="http://struts.apache.org/tags-logic" %>
<%@taglib prefix="b" uri="http://struts.apache.org/tags-bean" %>
<%@taglib prefix="h" uri="http://struts.apache.org/tags-html"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
            Collection<Integer> privileges = (Collection<Integer>) request.getSession().getAttribute(ConstantManager.SESSION_USER_PRIVILEGES);%>
<script language="JavaScript">
    <!--


    function openInNewWindow() {
        window.open(arguments[0],"actions" ,"menubar=yes,width=923,height=360,toolbar=no");
    }
</script>

<h1><b:message key="meetings_actions"/></h1>

<p>
    <b:message key="gen_show"/>
    <h:link action="/protected/actions_search?method=readActions"><b:message key="actions_all"/></h:link>|
    <h:link action="/protected/actions_search?method=readActions&status=pending"><b:message key="actions_pending"/></h:link>|
    <h:link action="/protected/actions_search?method=readActions&status=finished"><b:message key="actions_finished"/></h:link>

</p>
<h:form action="/protected/edit_actions?method=${param['method']}&clearStack=${param['clearStack']}">

    <div class="tabela">
        <table width="100%" border="0" >
            <tr>
                <%--<th scope="col"><b:message key="meetings_action_select_hint"/></th>--%>
                <th scope="col"><b:message key="meetings_action_action"/></th>
                <th scope="col"><b:message key="meetings_action_name"/></th>
                <th scope="col"><b:message key="meetings_action_status"/></th>
                <th scope="col"><b:message key="meetings_action_due_date"/></th>
                <th scope="col"></th>
            </tr>
            <l:empty name="ACTIONS_SEARCH_RESULTS">
                <tr class="red1">
                    <td colspan="9">
                        <div class="centeredinfo">
                            <img src="<%= request.getContextPath()%>/icons/info.png" align="top"/>
                            <b:message key="gen_no_search_results"/>

                        </div>
                    </td>
                </tr>
            </l:empty>



            <l:iterate id="actions" name="ACTIONS_SEARCH_RESULTS">


                <tr class="red1">

                    <%--<td>
                        <h:multibox property="selectedActions">
                            <b:write name="actions" property="id"/>
                        </h:multibox>
                    </td>--%>

                    <td>
                        <c:choose>
                            <c:when test="${actions.status == 'FINISHED'}">
                                <span class="finished"><b:write name="actions" property="actionText"/></span>
                            </c:when>
                            <c:otherwise>
                                <span><b:write name="actions" property="actionText"/></span>
                            </c:otherwise>
                        </c:choose>


                    </td>
                    <td>
                        <strong><b:write name="actions" property="name"/></strong>
                    </td>
                    <td>
                        <%--<h:select name="actions" property="status">
                            <h:option value="FINISHED"><b:message key="actions_finished" /></h:option>
                            <h:option value="PENDING"><b:message key="actions_pending" /></h:option>
                        </h:select>--%>
                        <c:choose>
                            <c:when test="${actions.status == 'FINISHED'}">
                                <b:message key="actions_finished" />
                            </c:when>

                            <c:when test="${actions.status == 'PENDING'}">
                                <b:message key="actions_pending" />
                            </c:when>

                        </c:choose>


                    </td>
                    <td>
                        <b:write name="actions" property="dueDate" format="dd/MM/yyyy"/>
                    </td>

                    <td>
                        <%
                                    if (privileges.contains(SecurityManager.EDIT_ACTIONS_PRIVILEGE)) {
                        %>
                        <a href="javascript:openInNewWindow('dispatch.do?method=showUpdateActionsForm&aid=${actions.id}');"><b:message key="gen_update"/></a>
                        <%}%>


                        <%
                                    if (privileges.contains(SecurityManager.DELETE_ACTIONS_PRIVILEGE)) {
                        %>
                        <h:link action="/protected/dispatcher?method=deleteActions&aid=${actions.id}"><b:message key="gen_delete"/></h:link>
                        <%}%>
                    </td>
                </tr>

            </l:iterate>

        </table>
        <%--<h:submit property="operation"><b:message key="gen_update"/></h:submit> <h:submit property="operation"><b:message key="gen_delete"/></h:submit>--%>

    </h:form>

<div id="navigation">

    <% AbstractPager pager = (AbstractPager) request.getSession().getAttribute(ConstantManager.SESSION_MEETING_PAGER);%>

    <c:if test="${MEETING_SEARCH_SHOW_PREV}">

        <a href="<%= request.getContextPath() + "/protected/meeting_search.do?method=showMeetings&p=" + (pager.getPageNumber() - 1)%>" class="previous"><b:message key="gen_previous"/></a>

    </c:if>


    <%-- padajuca lista sa brojevima strana --%>



    <select name="URL" onchange="window.location=this.options[selectedIndex].value">
        <%

                    Vector<Integer> pagenumbers = (Vector<Integer>) request.getAttribute("MEETING_SEARCH_PAGENUMBERS");
                    if (pagenumbers != null) { // if quicksearch is used
                        for (int i = 0; i < pagenumbers.size(); i++) {
                            int pageParam = pager.getPageNumber();
                            int pageNumber = pagenumbers.get(i);

                            if (pageParam == pageNumber) {
                                out.write("<option value=\"" + request.getContextPath() + "/protected/meeting_search.do?method=showMeetings&p=" + pageNumber + "\" selected=\"selected\">" + pageNumber + "</option>");
                            } else {
                                out.write("<option value=\"" + request.getContextPath() + "/protected/meeting_search.do?method=showMeetings&p=" + pageNumber + "\">" + pageNumber + "</option>");

                            }


                        }

                    }

        %>


    </select>




    <%-- end padajuca lista sa brojvima strana --%>



    <c:if test="${MEETING_SEARCH_SHOW_NEXT}">

        <a href="<%= request.getContextPath() + "/protected/meeting_search.do?method=showMeetings&p=" + (pager.getPageNumber() + 1)%>" class="next"><b:message key="gen_next"/></a>
    </c:if>
    <p>
        <b:message key="gen_items_showing"/> <%= pager.getItemInterval()%> <b:message key="gen_items_of_total"/> <%= pager.getResultsTotal()%>
    </p>
</div>
